import Vue from 'vue'
import Router from 'vue-router'

// 引入nprogess进度条插件
import NProgess from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/',
            name: 'login',
            component: () =>import ('@/pages/login/login'),
            meta: { title: '登录页' },
        },
        // 修改密码
        {
            path: '/Modifypassword',
            name: 'Modifypassword',
            component: () => import('@/pages/login/Modifypassword'),
            meta: {title: '修改密码'}
        },
        {
            path: '/home/',
            name: 'home',
            component: () => import('@/pages/home/home'),
            meta: { title: '首页' },
            children: [
                {
                    path: "setting",
                    name: "setTing",
                    component: () => import('@/pages/setTing/setting'),
                    meta: { title: "首页-设置" },
                },
                {
                    path: "myaccount",
                    name: "myaccount",
                    component: () => import('@/pages/setTing/myaccount/myaccount'),
                    meta: { title: "我的账号" }
                },
                {
                    path: "verification",
                    name: "verification",
                    component: () => import('@/pages/setTing/myaccount/verification'),
                    meta: { title: "验证手机" }
                },
                {
                    path: "Modifypassword",
                    name: "Modifypassword",
                    component: () => import('@/pages/setTing/myaccount/Modifypassword'),
                    meta: { title: "修改密码" }
                },
                {
                    path: "newphone",
                    name: "newphone",
                    component: () => import('@/pages/setTing/myaccount/newphone'),
                    meta: { title: "绑定新手机" }
                },
                {
                    path: "rolemanage",
                    name: "rolemanage",
                    component: () => import('@/pages/setTing/rolemanage/rolemanage'),
                    meta: { title: "角色管理" }
                },
                {
                    path: "editRole",
                    name: "editRole",
                    component: () => import('@/pages/setTing/EditRole'),
                    meta: { title: "编辑角色" }
                },
                {
                    path: "createRole",
                    name: "createRole",
                    component: () => import('@/pages/setTing/createRole'),
                    meta: { title: "创建角色" }
                },
                {
                    path: "datapermitmanage",
                    name: "datapermitmanage",
                    component: () => import('@/pages/setTing/datapermitmanage/datamanage'),
                    meta: { title: "数据权限管理" }
                },
                {
                    path: "userpermitmanage",
                    name: "userpermitmanage",
                    component: () => import('@/pages/setTing/userperimitamange/userpermitmanage'),
                    meta: { title: "用户权限管理" },
                },
                {
                    path: "accountmanage",
                    name: "accountmanage",
                    component: () => import('@/pages/setTing/accountmanage/accountmanage'),
                    meta: { title: "账号管理" },
                },
                // 员工管理
                {
                    path:"payroll",
                    name:"payroll",
                    component:() => import('@/pages/payroll/payroll'),
                    meta:{title:"发薪首页"},
                },
                // 发薪信息编辑
                {
                    path:"paurollCompile",
                    name:"paurollCompile",
                    component:() => import('@/pages/payroll/paurollCompile'),
                    meta:{title:"编辑发薪信息"},
                },
                // 查看发薪信息详情
                {
                    path:"paurollLook",
                    name:"paurollLook",
                    component:() => import('@/pages/payroll/paurollLook'),
                    meta:{title:"查看发薪信息详情"},
                },
                 // 创建发薪信息
                {
                    path:"paurollCreate",
                    name:"paurollCreate",
                    component:() => import('@/pages/payroll/paurollCreate'),
                    meta:{title:"创建发薪信息"},
                },
                {
                    path: 'company',
                    name: 'company',
                    component: () => import ('@/pages/company/company'),
                    meta: { title: '法人公司管理' }
                },
                {
                    path: 'companyCreate',
                    name: 'companyCreate',
                    component: () => import ('@/pages/company/companyCreate'),
                    meta: { title: '创建法人公司' }
                },
                {
                    path: 'companyEdit',
                    name: 'companyEdit',
                    component: () => import ('@/pages/company/companyEdit'),
                    meta: { title: '编辑法人公司' }
                },
                // 客户模块
                {
                    // 客户列表
                    path: 'customerList',
                    name: 'customerList',
                    component: () => import('@/pages/customer/customerList/customerList'),
                    meta: { title: '客户列表' }
                },
                {
                    // 编辑客户
                    path: '/edit',
                    name: 'edit',
                    component: () => import('@/pages/customer/edit/edit'),
                    meta: { title: '编辑客户' }
                },
                {
                    // 创建客户
                    path: '/establish',
                    name: 'establish',
                    component: () => import('@/pages/customer/establish/establish'),
                    meta: { title: '创建客户' }
                },
                {
                    // 查看详情
                    path: '/details',
                    name: 'details',
                    component: () => import('@/pages/customer/details/details'),
                    meta: { title: '查看详情' }
                },
                {
                    // 高级搜索
                    path: '/search',
                    name: 'search',
                    component: () => import('@/pages/customer/search/search'),
                    meta: { title: '高级搜索' }
                },
            ]
        }
    ]
});

// 配置路由全局前置守卫
router.beforeEach((to, from, next) => {
    let logintoken = localStorage.getItem("logintoken");
    NProgess.start();
    // 当访问登录页或存在token时放行，否则跳转到登录页
    if(to.path === '/' || logintoken){
        // 改变页面标题
        document.title = to.meta.title ? to.meta.title : "PC端后台系统";
        next();
    }else{
        // 改变页面标题，并结束进度条
        document.title = '登录页';
        NProgess.done();
        next({path:'/'});
    }
});

// 配置全局后置守卫
router.afterEach(() => {
    NProgess.done();
});

export default router;
